]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Make Source usable without subclassing
authorJasper St. Pierre <jstpierre@mecheye.net>
Fri, 7 Oct 2011 22:31:26 +0000 (18:31 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Thu, 17 May 2012 12:32:22 +0000 (08:32 -0400)
Rather than ask most users of Source to subclass it to simply set their icon,
just allow them to create a new instance and add it without any complex magic.

https://bugzilla.gnome.org/show_bug.cgi?id=661236

js/ui/messageTray.js

index 7358b289d26e38fa93194b6b2880459b1dcba4c9..b3da8c73e4e986e5b3312ea6731d8d08dbe77ef7 100644 (file)
@@ -960,8 +960,10 @@ const Source = new Lang.Class({
 
     ICON_SIZE: 24,
 
-    _init: function(title) {
+    _init: function(title, iconName, iconType) {
         this.title = title;
+        this.iconName = iconName;
+        this.iconType = iconType;
 
         this.actor = new Shell.GenericContainer();
         this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
@@ -991,6 +993,8 @@ const Source = new Lang.Class({
         this.isMuted = false;
 
         this.notifications = [];
+
+        this._setSummaryIcon(this.createNotificationIcon());
     },
 
     _getPreferredWidth: function (actor, forHeight, alloc) {
@@ -1061,10 +1065,12 @@ const Source = new Lang.Class({
     },
 
     // Called to create a new icon actor (of size this.ICON_SIZE).
-    // Must be overridden by the subclass if you do not pass icons
-    // explicitly to the Notification() constructor.
+    // Provides a sane default implementation, override if you need
+    // something more fancy.
     createNotificationIcon: function() {
-        throw new Error('no implementation of createNotificationIcon in ' + this);
+        return new St.Icon({ icon_name: this.iconName,
+                             icon_type: this.iconType,
+                             icon_size: this.ICON_SIZE });
     },
 
     // Unlike createNotificationIcon, this always returns the same actor;
@@ -1115,16 +1121,14 @@ const Source = new Lang.Class({
     },
 
     //// Protected methods ////
-
-    // The subclass must call this at least once to set the summary icon.
     _setSummaryIcon: function(icon) {
         if (this._iconBin.child)
             this._iconBin.child.destroy();
         this._iconBin.child = icon;
     },
 
-    // Default implementation is to do nothing, but subclasses can override
     open: function(notification) {
+        this.emit('opened', notification);
     },
 
     destroyNonResidentNotifications: function() {